const TILE_SIZE = 16;
//const TANK_SIZE = 32;

const tileCrop = {
  1: { x: 32, y: 96 },
  2: { x: 48, y: 96 },
  3: { x: 64, y: 96 },
  4: { x: 16, y: 96 },
  5: { x: 0,  y: 96 },
  9: { x: 256, y: 0 }
};

function generateMap(rows, cols) {
  const map = [];
  const midRow = Math.floor(rows / 2);
  const midCol = Math.floor(cols / 2);
  const laneRows = [Math.floor(rows / 4), midRow, Math.floor(rows * 3 / 4)];
  const towerCols = [Math.floor(cols / 4), midCol, Math.floor(cols * 3 / 4)];

  for (let i = 0; i < rows; i++) {
    const row = [];
    for (let j = 0; j < cols; j++) {
      let tile = 0;
      if (i === 0 && j === midCol || i === rows - 1 && j === midCol) tile = 5;
      else if (i === midRow && i < rows - 2) tile = 2;
      else if (laneRows.includes(i) && towerCols.includes(j)) tile = 1;
      else if (i === 0 || i === rows - 1 || j === 0 || j === cols - 1) tile = 4;
      else tile = 0;
      row.push(tile);
    }
    map.push(row);
  }
  return map;
}